﻿using Authentication.Configuration;
using Authentication.Model.Model;
using Common.Data.Extensions;
using System.Data.Entity.ModelConfiguration;

namespace Authentication.Data.DBConfig
{
    public class ObjectSubstitutionConfiguration : DBConfig<ObjectSubstitution>
    {
        public ObjectSubstitutionConfiguration()
            : base(SystemConfiguration.Schema, SystemConfiguration.NamingType, SystemConfiguration.TABLE_PREFIX)
        {
            HasKey(x => new { x.Id, x.ApplicationKey });

            Property(c => c.Id).IsRequired().HasMaxLength(32);
            Property(c => c.ObjectId).HasMaxLength(32);
            Property(c => c.ObjectNameLocal).HasMaxLength(100);
            Property(c => c.ObjectNameEnglish).HasMaxLength(100);
            Property(c => c.ParentId).HasMaxLength(32);
            Property(c => c.Active).HasMaxLength(1);

            //relationship  
            HasRequired(t => t.Object).WithMany(c => c.ObjectSubstitutions).HasForeignKey(t => new { t.ObjectId, t.ApplicationKey }).WillCascadeOnDelete(false);
        }
    }
}
